<?php


namespace platform\controllers;


use common\components\upload\Upload;
use yii\web\UploadedFile;

class UploadController extends BaseController
{
    public $modelClass = 'platform\models\File';

    public function actions()
    {
        $actions = parent::actions();

        // 禁用 "delete" 和 "create" 动作
        unset($actions['view'], $actions['delete'], $actions['create'], $actions['update']);

        return $actions;
    }

    public function actionCreate()
    {
        /** @var Upload $upload */
        $upload = \Yii::$app->upload;

        if ($upload->upload()) {
            return [
                'status' => 'done',
                'url' => \Yii::$app->params['staticDomain'] . $upload->relativePath,
                'fullUrl' => \Yii::$app->params['staticDomain'] . $upload->relativePath
            ];
        } else {
            return ['code' => 1, 'msg' => $upload->error];
        }
    }
}